from rest_framework.serializers import ModelSerializer

from .models import Area


class AreaSerializer(ModelSerializer):
    """省级序列化器"""

    class Meta:
        model = Area
        fields = ['id', 'name']


class SubAreaSerializer(ModelSerializer):
    """区县序列化器"""

    subs = AreaSerializer(many=True, read_only=True)  # 使用序列化器进行关联

    class Meta:
        model = Area
        fields = ['id', 'name', 'subs']